package org.yaukie.startup;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaukie.startup.inter.MyJobOnStartUpInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;
import java.util.Set;

/**
 *  @Author: yuenbin
 *  @Date :2020/5/16
 * @Time :14:26
 * @Motto: It is better to be clear than to be clever !
 * @Destrib:  定时任务启动总入口，将会随应用启动而启动
**/
@HandlesTypes(MyJobOnStartUpInitializer.class)
public class MyJobServletContainerInitializer implements ServletContainerInitializer{

	private static Logger logger = LoggerFactory.getLogger(MyJobServletContainerInitializer.class);

	@Override
	public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
		if(logger.isDebugEnabled())
		{
			logger.debug("定时任务初始化任务开始...");
		}
		for(Class<?> myJobOnStartUpInitializer : c ){
			try {
				MyJobOnStartUpInitializer startUpInitializer  = (MyJobOnStartUpInitializer) myJobOnStartUpInitializer.newInstance();
				startUpInitializer.init(ctx);
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		if(logger.isDebugEnabled())
		{
			logger.debug("定时器初始化任务结束...");
		}
	}

}
